<p>If your Microsoft® Expression Blend application does not behave the way that
you expect, or if errors occur when you try to build your application, there is a bug
in your application. It can be difficult to understand what is causing a bug or where
in your application it exists, but it helps to understand the types of bugs that you
might encounter.</p>
<a name="syntax"></a><h2>Syntax errors</h2>
<p>
When you build your application, any syntax errors are displayed in the
<strong>Errors</strong>
tab of the <strong>Results</strong> panel of Expression Blend, or in the <strong>Error
List</strong> panel in Microsoft® Visual Studio® 2005.</p>
<p>
Syntax errors occur if your Extensible Application Markup Language (XAML) or code does not follow the
formatting rules of the language. The description of the error
can help you understand how to fix it. The description also specifies the name of the
file and the line number where the error occurs. Some common causes of syntax
errors are as follows:</p>
<ul>
<li>A keyword has been misspelled or the capitalization is wrong.</li>
<li>Quotation marks are missing around strings of text.</li>
<li>A XAML element is missing a closing tag.</li>
<li>A XAML element exists in a location where it is not allowed. You can avoid
these errors by editing your documents in <strong>Design</strong> view in Expression
Blend, or in Visual Studio 2005 with the extensions for .NET Framework 3.0
installed. The extensions can be downloaded from <a target="_blank" href="http://go.microsoft.com/fwlink/?linkid=74081">MSDN</a>. </li>
<li>In a code file, a function or method call does not include the required
parameters. For example, the <code>MessageBox.Show()</code> method must have at
least one parameter, such as a string, <code>MessageBox.Show("Hello")</code>.</li>
<li>In a code file, a variable of one type is being assigned to a different
type. For example, the <code>MessageBox.Show()</code> method can have a string argument, but it cannot have an integer argument.</li>
<li>In C#, a method that does not need arguments might not have braces at the
end. For example, <code>this.InitializeComponent;</code> will cause a syntax error because
the correct line is <code>this.InitializeComponent</code>()<code>;</code>.</li>
</ul>
<p>
For information about XAML syntax, see the overview topics for individual
controls listed in the "Control Library" topic in the Windows Presentation Foundation
(WPF) section
on <a target="_blank" href="http://go.microsoft.com/fwlink/?linkid=74081">MSDN</a>. For information about programming syntax, you can search on MSDN for
keywords in your code. </p>
<a name="compile"></a><h2>Compilation errors</h2>
<p>When you build your application, any compilation errors are displayed
in the
<strong>Errors</strong>
tab of the <strong>Results</strong> panel of Expression Blend, or in the <strong>Error
List</strong> panel in Visual Studio 2005.</p>
<p>Compilation errors occur when the compilation system of Expression
Blend or Visual Studio 2005 cannot find something that your project requires.
For example, if your project is missing a reference to the WPF assemblies, you might get an error such as "The name
'Window' does not exist in namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'".
If you get this error, you can click <strong>Add Reference</strong> on the
<strong>Project</strong> menu to add references to the following WPF assemblies
in the C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 folder:</p>
<ul><li>PresentationCore.dll</li>
<li>PresentationFramework.dll</li>
<li>WindowsBase.dll</li></ul>
<p>If you still receive errors such as "The name '<em><member></em>' does not exist
in the current context.", there might be another assembly reference missing,
or you might need to add a <strong>using</strong> (C#) or <strong>Imports</strong>
(Visual Basic .NET) statement to your code for the missing namespace. To find out which
assembly or namespace is required, see the MSDN reference topic for the
member that is causing the error.</p>
<p>Some other common causes for compilation errors are as follows:</p>
<ul>
<li>A keyword has been misspelled or the capitalization is wrong.</li>
<li>A class is not referenced properly in your application. For example, if your
application uses a custom class which is implemented
in a separate .cs or .vb code file with its own namespace, any document in your
application that uses the custom class needs to include
a line like the following, where <code>FullyQualifiedNamespace</code> is the namespace in the
<li>In a code file, a variable references an object that does not yet exist. For
example, in a code-behind file, you can not reference a XAML object before the line
<code>this.InitializeComponent();</code>, otherwise you will get a <strong>XamlParseException</strong>
error.</li>
<li>In a code file, assumptions are made that make your application progress
down an unexpected code path. This situation benefits most from stepping through
your code while debugging your application in Visual Studio 2005. For more
information, see <a href="task_debugginginvs.htm">Debugging Expression Blend
applications in Visual Studio</a> in this User Guide.</li>
<li>In a code-behind file, user interface (UI) updates are executed on the same thread as other
programming logic that should be performed on a separate thread. For example, if you create an event handler method that
updates the text that is displayed in a <strong>Label</strong>, performs some other calculations, and then updates the
text in the same <strong>Label</strong> again before the event handler method
completes, you will only see the last update. This is because the rendering of
your UI occurs at the end of your event handler method and all processing is
done on the same thread, so your application cannot take time out during the
execution of your method to update the UI. For information about how to write
WPF applications that have multiple UI updates and calculations, see
"Threading Model"
in the WPF section
on <a target="_blank" href="http://go.microsoft.com/fwlink/?linkid=74081">MSDN</a>
. </li>
<li>In an event handler method in a code-behind file, UI elements or their
properties are referenced before they are available. For example, in
your Window1() constructor method, you will not be able to access UI elements
yet. In an OnInitialized() event handler method, you can access UI elements, but you cannot examine properties like ActualWidth because the UI elements have not been laid
out yet. In an OnLoaded() event handler method, you can do anything you need to
do with UI elements that exist in your XAML document. For more information, see
"Object Lifetime Events"
in the WPF section
on <a target="_blank" href="http://go.microsoft.com/fwlink/?linkid=74081">MSDN</a>
. For a
list of events and when they occur, see the
<a href="../reference/reference_events.htm">
Events quick reference</a> in this User Guide.</li>
</ul>
<a name="vsdebug"></a><h2>Debugging in Visual Studio 2005</h2>
<p>Expression Blend is a design tool for creating rich user interfaces and Windows®-based applications
that make use of WPF features. You can use Visual Studio 2005, which is also used to build
Windows-based applications, to open, build, and debug Expression Blend projects.
If you are having trouble debugging your application by using the <strong>Test</strong>
(F5) feature of Expression Blend, you can use Visual Studio 2005 to obtain
detailed error messages about run-time errors. For more information, see
<p>If you have an application that uses both WPF and another technology like
Windows Forms programming, you may experience problems such as unexpected
overlapping behavior, scaling behavior, control focus issues, and so on. For
information that can help you debug hybrid applications, see "Troubleshooting Hybrid Applications in the WPF section
on <a target="_blank" href="http://go.microsoft.com/fwlink/?linkid=74081">MSDN</a>.</p>
<a name="security"></a><h2>Security</h2>
<p>While being debugged, your application has the same security permissions that
it has when another person uses it. For more information, see <a href="concept_deployment.htm">Deploying and publishing Expression Blend applications</a>
in this User Guide. For more information about WPF application security, see
"Security" in the WPF section
on <a target="_blank" href="http://go.microsoft.com/fwlink/?linkid=74081">MSDN</a>.</p>
<a name="help"></a><h2>Getting help</h2>
<p>If you need more help debugging your Expression Blend application, you can
search on <a target="_blank" href="http://go.microsoft.com/fwlink/?linkid=83197">Windows Presentation Foundation Forum</a> for posts related your issue or post a question.</p>